package br.ufmg.dees.insane.ui.rich.prep.view.dialog;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;

import br.ufmg.dees.insane.ui.rich.prep.view.DesktopPrep;

/**
 * The class with the main method.
 * @author Ferreira, Reginaldo & Pitangueira, Roque
 * @since october 2006
 */ 
public class DesktopSimpleDialog extends JDialog implements ActionListener
{
	private static final long serialVersionUID = 1L;
	public static final int OK_OPTION = 0;
    public static final int CANCEL_OPTION = 1;
    
	private JPanel mainPane = new JPanel();
	private JButton btn_Ok, btn_Cancel;
	private int option_Button = CANCEL_OPTION;
	private Container container;
	
//	****************************************************************************

	// Constructors 
    public DesktopSimpleDialog(DesktopPrep parent, String title)
	{
    	super(parent, title, true);

        btn_Ok = new JButton("Ok");
        btn_Ok.addActionListener(this);
        getRootPane().setDefaultButton(btn_Ok);
          
        btn_Cancel = new JButton("Cancel");
        btn_Cancel.addActionListener(this);
        
        JPanel buttonsPane = new JPanel();
        buttonsPane.setLayout(new FlowLayout(FlowLayout.CENTER));
        //buttonsPane.setBorder(BorderFactory.createEtchedBorder());
        buttonsPane.add(btn_Ok);
        buttonsPane.add(btn_Cancel);

    	container = getContentPane();
    	container.setLayout(new BorderLayout());
        container.add(mainPane, BorderLayout.CENTER);
        container.add(buttonsPane, BorderLayout.SOUTH);  
    }
    
//	**************************************************************************** 
    
    public void actionPerformed(ActionEvent e) {
        
        if(e.getSource() == btn_Ok)
    	{
			this.setVisible(false);
			this.option_Button = OK_OPTION;	
    	}
        else
        {
        	this.setVisible(false);
        	this.option_Button = CANCEL_OPTION;
        }
    }
    
//	****************************************************************************
    
	public void setPane(JPanel pane)
	{
		this.mainPane.add(pane);
	}
	
//	****************************************************************************
    
	public void setDlgSize(int w, int h)
	{
		this.setSize(w, h);
	}	
	
//	****************************************************************************
	
    public int getOptionButton()
    {
    	return this.option_Button;
    }     

//	**************************************************************************** 
    
    public void windowClosing (WindowEvent e)
    { 
    	System.exit(0); 
    } 
    
//	****************************************************************************   
}//end of this class

